package com.goldplusgold.tradedelay.app.my.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.goldplusgold.live.bean.LikeBean;
import com.goldplusgold.imageloader.lib.GlideCircleTransform;
import com.goldplusgold.tradedelay.app.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/7/24.
 */

public class MyFollowAdapter extends RecyclerView.Adapter<MyFollowAdapter.MyFollowHolder> {
    private Context mContext ;
    private List<LikeBean> lists ;
    private MyFollowAdapterListener listener ;

    public MyFollowAdapter(Context mContext , List<LikeBean> lists , MyFollowAdapterListener listener){
        this.mContext = mContext ;
        this.lists = lists ;
        this.listener = listener ;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public MyFollowHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View ItemView = LayoutInflater.from(mContext).inflate(R.layout.item_my_follow , parent ,false);
        return new MyFollowHolder(ItemView);
    }

    @Override
    public void onBindViewHolder(MyFollowHolder holder, int position) {
        holder.follow_cancel_tv.setTag(position);
        holder.follow_item_rl.setTag(position);
        Glide.with(mContext).load(lists.get(position).getColumnIcon())
                .bitmapTransform(new GlideCircleTransform(mContext)).into(holder.follow_icon_iv);
        holder.follow_name_tv.setText(lists.get(position).getColumnName());
        holder.follow_message_tv.setText(lists.get(position).getColumnIntro());
    }

    @Override
    public int getItemCount() {
        return lists.size();
    }

    public class MyFollowHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.follow_icon_iv)
        ImageView follow_icon_iv ;
        @BindView(R.id.follow_name_tv)
        TextView follow_name_tv ;
        @BindView(R.id.follow_cancel_tv)
        TextView follow_cancel_tv;
        @BindView(R.id.follow_item_rl)
        RelativeLayout follow_item_rl ;
        @BindView(R.id.follow_message_tv)
        TextView follow_message_tv ;

        @OnClick(R.id.follow_cancel_tv)
        void follow_Cancel(View view){
            int pos = (int) view.getTag();
            listener.clickCancel(lists.get(pos).getColumnID());
        }
        @OnClick(R.id.follow_item_rl)
        void GotoColumn(View view){
            int pos = (int) view.getTag();
            listener.clickItem(pos);
        }

        public MyFollowHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this , itemView);
        }
    }

    public interface MyFollowAdapterListener{
        public void clickCancel(String columnID);

        public void clickItem(int pos);
    }
}
